package com.java.caiquan;

import java.util.Scanner;
import java.util.concurrent.BrokenBarrierException;

public class Game {
    public static Scanner scanner = new Scanner(System.in);

    private  static user user1;
    private static Computer computer;
    static {
        user1 = new user();
        computer = new Computer();

    }
    public void startGame(){
        System.out.println("********************欢迎来到游戏世界****************\n"+"出拳规则：1.剪刀 2.石头 3.布");
       //选角色
        choosename();
        //开始战斗吧？
        System.out.println("要开始干吗？y/n ?");
        String str = scanner.next();
        if(!"y".equals(str)){
            System.out.println("拜拜，不玩就滚吧你！");
            return;
        }
        System.out.println("请输入您的大名？何方神圣？来打我？");
        user1.setUsername(scanner.next());


        String nextba;
        int count = 0;
        do {
            showbattleresult();
            count++;
            System.out.println("还要跟我比下一把吗？怂货,y/n");
            nextba = scanner.next();
        } while ("y".equals(nextba));
        System.out.println("果然就不是我的对手，电脑就算6核也不过如此！");
//显示最终成绩在结尾的时候
        ShowFinalScore(count);

    }

    private void ShowFinalScore(int count) {
        String username = user1.getUsername();
        int  score = user1.getScore();
        String name = computer.getName();
        int score2 = computer.getScore();
        System.out.println(username  + "vs" + name);
        System.out.println("对战次数" + count);
        System.out.println("得分如下");
        System.out.println(name + "的得分是" + score2);
        System.out.println(username + "的得分是" + score);
        if(score == score2){
            System.out.println("玩了半天是平局，真的他娘的浪费时间，还没劲头");
        }else if(score > score2){
            System.out.println("这回真的是"+ username +"赢了，人还是比电脑厉害的");
        }else  {
            System.out.println("这回是"+ name +"赢了，电脑越来越厉害了，赶紧学AI吧，柯洁也打不过阿尔法狗了！");
        }
    }

    private void showbattleresult() {
       int A = user1.FIGHT(scanner);
      int B =  computer.chuquan();
      int num = A - B;
      if(num == 0){
          System.out.println("是平局，不公平，重新比赛！");
      }else if(num == 2 || num == -1){
          System.out.println(user1.getUsername() +"赢了，果然人类还是强的！!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            user1.setScore(user1.getScore() + 1);
      }
      else{
          System.out.println(computer.getName() +"赢了,赶紧学AI吧，电脑太厉害了现在！++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            computer.setScore(computer.getScore() + 1);
      }

    }

    private void choosename() {
        System.out.println("请选择对方的角色《1.刘备 2.孙权 3.曹操 4。张飞》");
        int choice = scanner.nextInt();
        String rolename = "";
        switch (choice){
            case 1:
                rolename = "刘备";
                break;
            case 2:
                rolename = "孙权";
                break;
            case 3:
                rolename = "曹操";
                break;
            case 4:
                rolename = "张飞";
                break;
            default:
                rolename = "请选择有效角色，别整那么多没有的";
        }
        System.out.println("您选择的角色是"+rolename);
        computer.setName(rolename);
}

}
